package com.gxa.logistics.service.impl;

import com.github.pagehelper.PageHelper;
import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.common.util.PageResultUtil;
import com.gxa.logistics.domain.dto.InsuranceReqListDTO;
import com.gxa.logistics.domain.dto.InsuranceSaveDTO;
import com.gxa.logistics.domain.dto.InsuranceUpdateDTO;
import com.gxa.logistics.domain.vo.InsuranceVO;
import com.gxa.logistics.mapper.InsuranceMapper;
import com.gxa.logistics.service.InsuranceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InsuranceServiceImpl implements InsuranceService {
    @Autowired
    private InsuranceMapper insuranceMapper;
    @Override
    public RespResult<PageWrapperDTO<InsuranceVO>> list(InsuranceReqListDTO insuranceReqListDTO) {
        // 使用分页插件
        PageHelper.startPage(insuranceReqListDTO.getPageNo(),insuranceReqListDTO.getPageSize());
        // 包装的分页返回对象
        PageWrapperDTO<InsuranceVO> pageCommon = new PageWrapperDTO<>();
        List<InsuranceVO> insuranceList = insuranceMapper.findInsuranceByWhere(insuranceReqListDTO);
        // 设置分页返回对象
        PageResultUtil.setPageResult(insuranceList,pageCommon);
        return RespResult.success(pageCommon);
    }

    @Override
    public void insertInsurance(InsuranceSaveDTO insuranceSaveDTO) {
            insuranceMapper.insertInsurance(insuranceSaveDTO);
    }

    @Override
    public void updateInsurance(InsuranceUpdateDTO insuranceUpdateDTO) {
            insuranceMapper.updateInsurance(insuranceUpdateDTO);
    }

    @Override
    public void deleteInsuranceByLpnum(String lpnum) {
            insuranceMapper.deleteInsuranceByLpnum(lpnum);

    }


}
